<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link type="text/css" rel="stylesheet" href="__STATIC__/uploads/css/fileinput.css"/>
    <script type="text/javascript" src="__STATIC__/uploads/js/fileinput.js"></script>
    <script type="text/javascript" src="__STATIC__/uploads/js/fileinput_locale_zh.js"></script>
    <link type="text/css" rel="stylesheet" href="__STATIC__/uploads/css/bootstrap.min.css"/>
</head>
<body>
<form class="layui-form" action="" onsubmit="return false" id="image" style="width: 400px;padding-top: 5px">
    <input type="hidden" name="id" value="{$data.id}">
    <input type="hidden" name="img" value="" id="imgs" lay-verify="imgs">
    <div class="layui-form-item">
        <label class="layui-form-label">原图片</label>
        <div class="layui-input-block">
            <img src="/banner/{$data.photo}" width="100px" height="100px">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="uploads">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
    <div id="upload_img" style="display: none">
        <label class="layui-form-label">新图片</label>
        <div class="layui-input-block">
            <img src="" id="new_img" width="100px" height="100px">
        </div>
    </div>
    <div class="layui-form-item" style="padding-top: 5px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*" id="update">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['upload','form'], function(){
        var upload = layui.upload;
        var form = layui.form;
        //执行实例
        upload.render({
            elem: '#uploads' //绑定元素
            ,data:{path:'public/banner'}
            ,field:'file'
            ,url: '/common/img' //上传接口
            ,done: function(res){
                if(res.code){
                    $("#upload_img").css('display','block');
                    $("#new_img").attr('src',"/banner/"+res.img);
                    $("#imgs").val(res.img);
                }else{
                    layer.msg(res.error,{icon:5,time:2000})
                }
            }
        });
        form.verify({
            imgs:function (value) {
                if(value.length < 0){
                    return '请上传图片';
                }
            }
        });
        form.on('submit(*)', function(data) {
            $.ajax({
                type:'POST',
                url:'/banner/updateImage',
                data:$("#image").serialize(),
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    });
</script>
</body>
</html>